package com.lyhengtongwl.zqsnews.adapter;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lyhengtongwl.zqsnews.App;
import com.lyhengtongwl.zqsnews.R;
import com.lyhengtongwl.zqsnews.entity.NewsDDEntity;
import com.lyhengtongwl.zqsnews.utils.FTYUtils;
import com.makeramen.roundedimageview.RoundedImageView;
import com.squareup.picasso.Picasso;

import java.util.List;

public class NewsDDAdapter extends BaseQuickAdapter<NewsDDEntity, BaseViewHolder> {
    private Activity activity;
    private String type;

    public NewsDDAdapter(Activity activity, List<NewsDDEntity> newsList,String type) {
        super(R.layout.item_dd, newsList);
        this.activity = activity;
        this.type=type;
    }


    @SuppressLint("SetTextI18n")
    @Override
    protected void convert(BaseViewHolder helper, NewsDDEntity item) {
        ImageView detail=helper.getView(R.id.iv_detail);
        ((TextView) helper.getView(R.id.tv_id)).setText("ID：" + item.getId());
        ((TextView) helper.getView(R.id.tv_time)).setText("注册时间：" + (item.getTime()).substring(0, 10));
        switch (type){
            case "0":
                detail.setVisibility(View.VISIBLE);
                break;
            case "1":
                detail.setVisibility(View.GONE);
                break;
        }
        if ("0".equals(item.getMoney1())) {
            ((TextView) helper.getView(R.id.tv_money)).setText(item.getMoney1());
        }else {
            ((TextView) helper.getView(R.id.tv_money)).setText(FTYUtils.fenToYuan(item.getMoney1()));
        }
        if ("0".equals(item.getMoney2())) {
            ((TextView) helper.getView(R.id.tv_money1)).setText(item.getMoney2());
        }else {
            ((TextView) helper.getView(R.id.tv_money1)).setText(FTYUtils.fenToYuan(item.getMoney2()));
        }

        Picasso.with(App.getContext()).load(item.getImgUrl()).placeholder(R.mipmap.head).error(R.mipmap.head).into((RoundedImageView) helper.getView(R.id.iv_head));
    }
}
